/**
 *
 */
package com.cmcc.pcap.jpcap.tcp.tcp;

import java.util.Date;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.cmcc.packet.entity.TcpEntity;
import com.cmcc.pcap.jpcap.tcp.TcpConnection;
import com.cmcc.pcap.jpcap.tcp.TcpPacketDecorator;
import com.cmcc.pcap.jpcap.tcp.TcpProtocolHandler;
import com.cmcc.pcap.jpcap.tcp.tcp.xdr.TcpXdrGenerate;


/**
 * @Date 2018年3月21日 上午10:06:33
 * @author Amish
 *
 */
public class TcpHandler extends TcpProtocolHandler <TcpEntity>{

	private static Logger logger = LogManager.getLogger(TcpHandler.class);
	private TcpXdrGenerate txg = new TcpXdrGenerate();
	@Override
	public List<TcpEntity> handle(TcpConnection tcpConnection, String taskId) {
		logger.debug("start execute tcp packet handler");
		logger.debug(new Date(tcpConnection.lastPacketTime));
		long pcapTimestamp = ((TcpPacketDecorator) tcpConnection.al.get(tcpConnection.al.size() - 1)).tcpPacket.sec
				* 1000L;
		logger.debug(new Date(pcapTimestamp));
		List<TcpEntity> xdrTcpEntityList = this.txg.generate(tcpConnection,taskId);
		logger.debug("this connection <" + tcpConnection.connectionKey + "> save into tcp packet entity !");
//		PcapTcpDao.save(this.txg.xdrtcpEntityList, taskId);
//		this.txg.xdrtcpEntityList.clear();
		logger.debug("this connection <" + tcpConnection.connectionKey + "> saved into database !");
		return xdrTcpEntityList;
	}

}
